<template>
  <div>
    <el-dialog
      v-model="dialogTableVisible"
      title="Shipping address"
      ref="multipleTableRef"
      style="width: 100%"
    >
      <el-table ref="tableRef" :data="gridData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" />
        <el-table-column property="date" label="Date" width="150" />
        <el-table-column property="name" label="Name" width="200" />
        <el-table-column property="address" label="Address" />
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="outerVisible">Cancel</el-button>
          <!-- <el-button type="primary" @click="handleSelectionChange">
          open the inner Dialog
        </el-button> -->
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  reactive,
  onMounted,
  ref,
  watch,
  nextTick,
} from "vue";

export default defineComponent({
  emits: ["removeItem"],
  components: {},
  props: {},
  setup(props, ctx) {
    const dialogTableVisible = ref(false);
    const dialogFormVisible = ref();
    const formLabelWidth = "140px";

    const form = reactive({
      name: "",
      region: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });

    const gridData = [
      {
        date: "2016-05-02",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
      {
        date: "2016-05-04",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
      {
        date: "2016-05-01",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
      {
        date: "2016-05-03",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
    ];
    const multipleTableRef = ref();
    const dataList = ref();
    const handleSelectionChange = (val) => {
      dataList.value = val;
      console.log(123, val);
    };

    const outerVisible = () => {
      dialogTableVisible.value = false;
      ctx.emit("removeItem", dataList.value);
    };
    const tableRef=ref()
    const open = (rows) => {
      console.log(3339,rows);
      dialogTableVisible.value = true;
      // multipleTableRef.value.toggleRowSelection()
      toggleSelection1(rows);
    };
    const toggleSelection1 = (rows) => {
      setTimeout(() => {
        nextTick(() => {
            console.log(5,tableRef.value);
            
          tableRef.value.toggleRowSelection(rows, true);
        });
      }, 2000);
    };
    return {
      gridData,
      form,
      dialogFormVisible,
      formLabelWidth,
      dialogTableVisible,
      multipleTableRef,
      dataList,
      tableRef,
      handleSelectionChange,
      outerVisible,
      open,
    };
  },
});
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
